﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;

namespace $safeprojectname$
{
    public enum ButtonType
    {
        Button,
        Reset,
        Submit
    }

    /// <summary>
    ///     renders &lt;BUTTON&gt; element with provided Text (innerText) instead of a value attribute.
    ///     (IE prefered...)
    /// </summary>
    public class Button : ContentControl<ICoreModel, Button>
    {
        #region members
        Literal _literal = new Literal();
        #endregion members

        #region constructor
        public Button(string text = null, bool doLocalize = true, string cssClassName = null)
            : base(cssClassName)
        {
            Controls.Add(_literal);
            _literal.SetText(text, doLocalize);
            SetType(ButtonType.Button);
        }
        #endregion constructor

        #region Set
        public virtual Button SetText(string text, bool doLocalize = true)
        {
            Literal.SetText(text, doLocalize);
            return this;
        }

        public virtual Button SetType(string typeName)
        {
            Type = typeName;
            return this;
        }

        public Button SetType(ButtonType type)
        {
            switch (type)
            {
                case ButtonType.Submit:
                    Type = ButtonTypes.Submit;
                    break;
                case ButtonType.Reset:
                    Type = ButtonTypes.Reset;
                    break;
                default:
                    Type = ButtonTypes.Button;
                    break;
            }
            return this;
        }

        public virtual Button SetName(string name)
        {
            Name = name;
            return this;
        }

        public virtual Button SetDisabled(bool isDisabled)
        {
            if (isDisabled)
            {
                Disabled = Attr.Disabled;
            }
            else
            {
                Attributes.Remove(Attr.Disabled);
            }
            return this;
        }

        public virtual Button SetAccessKey(string accessKey)
        {
            AccessKey = accessKey;
            return this;
        }
        #endregion Set

        #region properties
        protected override string TagName
        {
            get { return Tag.Button; }
        }

        protected virtual Literal Literal
        {
            get { return _literal; }
            set { _literal = value; }
        }

        public string Type
        {
            get { return GetAttribute(Attr.Type); }
            set { SetAttribute(Attr.Type, value); }
        }

        public virtual string Disabled
        {
            get { return GetAttribute(Attr.Disabled); }
            set { SetAttribute(Attr.Disabled, value); }
        }

        public virtual string Name
        {
            get { return GetAttribute(Attr.Name); }
            set { SetAttribute(Attr.Name, value); }
        }

        public virtual string AccessKey
        {
            get { return GetAttribute(Attr.AccessKey); }
            set { SetAttribute(Attr.AccessKey, value); }
        }
        #endregion properties
    }
}